package program

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method 'GET'
        url value(consumer(regex('/api/programs/workspace')),
                producer('/api/programs/workspace'))
        headers {
            contentType(applicationJsonUtf8())
            header("id", 1)
        }
    }
    response {
        status 200
        body("""
            {
                "content": [
                  {
                    "id": 1,
                    "createTime": "2016-09-09 00:00:00.0",
                    "creatorId": 2,
                    "introduction": "program introduction"
                  }
                ],
                "totalPages": 1,
                "pageable": {
                    "pageSize": 20
                }
            }
        """)
        bodyMatchers {
            jsonPath('$.content', byType())
            jsonPath('$.content.[*].id', byRegex(number()))
            jsonPath('$.content.[*].createTime', byRegex(nonEmpty()))
            jsonPath('$.content.[*].creatorId', byRegex(number()))
            jsonPath('$.content.[*].introduction', byRegex(nonEmpty()))
            jsonPath('$.totalPages', byRegex(number()))
            jsonPath('$.pageable', byType())
            jsonPath('$.pageable.pageSize', byRegex(number()))
        }
        headers {
            contentType(applicationJsonUtf8())
        }
    }

}